clear all; close all; clc;


R=47;%Om
L=100e-6;%Hn


fsr=1/(6*pi*L/R);
fn=fsr/1000;
fprintf('fsr = %f,kHz\n', fn)


Tmod=1000*L/R;
T=R/(100*L);
t=0:T:Tmod;


fmin=0;
fmax=2*fsr;
f=fmin:((fmax-fmin)/100):fmax;
K=nan(1,length(f));
for j=1:length(f);
    E=sin(2*pi*f(j)*t);

UL=nan(1,length(t));
UR=nan(1,length(t));
i=nan(1,length(t));
di=nan(1,length(t));


UL(1)=E(1); i(1)=0;


 for j=2:length(t);
    UL(k)=E(k)-3*UR(k);
    di(k)=UL(k)/L;
    i(k)=i(k-1)+di(k-1)*T;
    UR(k)=i(k)*R;
    
 end  
Us=UR(fix(end/2):end);
K(k)=(max(Us)-min(Us))/2;
end

    figure;
    plot(f,20*log10(K))
    xlabel('f,Hz');
    ylabel('K');
